package ${package.Controller};



import org.springframework.beans.factory.annotation.Autowired;
import com.yaofeng.mybatis.modules.${package.ModuleName}.service.${table.serviceName};
import com.yaofeng.mybatis.modules.${package.ModuleName}.entity.${entity};
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yaofeng.mybatis.annotation.Log;
import com.yaofeng.mybatis.common.PageInfo;
import com.yaofeng.mybatis.common.ResponseInfo;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {

    @Autowired
    private ${table.serviceName} ${(table.serviceName?substring(1))?uncap_first};

    @GetMapping("/list")
    @RequiresAuthentication
    @Log(value = "列表")
    public ResponseInfo list(@RequestParam Map<String, Object> params, @RequestParam(defaultValue = "1") Long pageNum, @RequestParam(defaultValue = "50") Long pageSize) {
        IPage page = ${(table.serviceName?substring(1))?uncap_first}.page(new Page<>(pageNum, pageSize), Wrappers.<${entity}>lambdaQuery());
        return ResponseInfo.success(new PageInfo(page));
    }

     /**
     * 保存
     * @param ${entity?uncap_first}
     * @return
     */
    @PostMapping("/save")
    @RequiresAuthentication
    @Log(value = "保存")
    public  ResponseInfo save(@RequestBody ${entity} ${entity?uncap_first}){
        ${(table.serviceName?substring(1))?uncap_first}.save(${entity?uncap_first});
        return ResponseInfo.success();
    }


    /**
     * 更新
     * @param ${entity?uncap_first}
     * @return
     */
    @PutMapping("/update")
    @RequiresAuthentication
    @Log(value = "更新")
    public  ResponseInfo update(@RequestBody  ${entity} ${entity?uncap_first}){
        ${(table.serviceName?substring(1))?uncap_first}.updateById(${entity?uncap_first});
        return ResponseInfo.success();
    }


    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping ("/delete")
    @RequiresAuthentication
    @Log(value = "删除")
    public  ResponseInfo delete(Long id){
       ${(table.serviceName?substring(1))?uncap_first}.removeById(id);
        return ResponseInfo.success();
    }



</#if>

}
</#if>
